<div [@routerTransition]>

    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("Languages")}}</span>
                </h3>
                <span class="m-section__sub">
                    {{l("LanguagesHeaderInfo")}}
                </span>
            </div>
            <div class="col-xs-6 text-right">
                <button *ngIf="isGranted('Pages.Administration.Languages.Create') && multiTenancySideIsHost" (click)="createOrEditLanguageModal.show()" class="btn btn-primary"><i class="fa fa-plus"></i> {{l("CreateNewLanguage")}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="row align-items-center">
                    <!--<Primeng-TurboTable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable
                                 (onLazyLoad)="getLanguages()"
                                 [value]="primengTableHelper.records"
                                 rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                 [paginator]="false"
                                 [lazy]="true"
                                 [responsive]="primengTableHelper.isResponsive">
                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width: 130px"
                                        [hidden]="!isGrantedAny('Pages.Administration.Languages.Edit', 'Pages.Administration.Languages.ChangeTexts', 'Pages.Administration.Languages.Delete')">
                                        {{l('Actions')}}
                                    </th>
                                    <th>
                                        {{l('Name')}}
                                    </th>
                                    <th>
                                        {{l('Code')}}
                                    </th>
                                    <th *ngIf="appSession.tenantId ? true : false">
                                        {{l('Default')}} *
                                    </th>
                                    <th>
                                        {{l('CreationTime')}}
                                    </th>
                                    <th>
                                        {{l('IsEnabled')}}
                                    </th>
                                </tr>
                            </ng-template>
                            <ng-template pTemplate="body" let-record="$implicit">
                                <tr>
                                    <td style="width: 130px; text-align: center">
                                        <div class="btn-group dropdown">
                                            <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown"
                                                    aria-haspopup="true"
                                                    aria-expanded="false">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a *ngIf="permission.isGranted('Pages.Administration.Languages.Edit') && record.tenantId === appSession.tenantId"
                                                       (click)="createOrEditLanguageModal.show(record.id)">{{l('Edit')}}</a>
                                                </li>
                                                <li>
                                                    <a *ngIf="permission.isGranted('Pages.Administration.Languages.ChangeTexts')"
                                                       (click)="changeTexts(record)">{{l('ChangeTexts')}}</a>
                                                </li>
                                                <li>
                                                    <a *ngIf="permission.isGranted('Pages.Administration.Languages.Edit')"
                                                       (click)="setAsDefaultLanguage(record)">{{l('SetAsDefaultLanguage')}}</a>
                                                </li>
                                                <li>
                                                    <a *ngIf="permission.isGranted('Pages.Administration.Languages.Delete') && record.tenantId === appSession.tenantId"
                                                       (click)="deleteLanguage(record)">{{l('Delete')}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('Name')}}</span>
                                        <span [ngClass]="{'text-bold' : defaultLanguageName === record.name}">
                                            <i [ngClass]="record.icon" class="margin-right-5"></i>
                                            {{record.displayName}} <span *ngIf="defaultLanguageName === record.name">({{l('Default')}})</span>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('Code')}}</span>
                                        {{record.name}}
                                    </td>
                                    <td *ngIf="appSession.tenantId ? true : false">
                                        <span class="ui-column-title">{{l('Default')}}</span>
                                        <span class="label m-badge m-badge--success m-badge--wide"
                                              *ngIf="record.tenantId !== appSession.tenantId">
                                            {{l('Yes')}}
                                        </span>
                                        <span class="label m-badge m-badge--metal m-badge--wide"
                                              *ngIf="record.tenantId === appSession.tenantId">
                                            {{l('No')}}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('CreationTime')}}</span>
                                        {{record.creationTime | momentFormat:'L'}}
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('IsEnabled')}}</span>
                                        <span class="label m-badge m-badge--success m-badge--wide"
                                              *ngIf="!record.isDisabled">
                                            {{l('Yes')}}
                                        </span>
                                        <span class="label m-badge m-badge--metal m-badge--wide"
                                              *ngIf="record.isDisabled">
                                            {{l('No')}}
                                        </span>
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>
                        <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                            {{l('NoData')}}
                        </div>
                        <div class="ui-table-footer">
                            {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->

                    <p class="margin-top-20" *ngIf="appSession.tenantId">
                        * {{l("CanNotEditOrDeleteDefaultLanguages")}}
                    </p>

                </div>
            </div>
        </div>
    </div>

    <createOrEditLanguageModal #createOrEditLanguageModal (modalSave)="getLanguages()"></createOrEditLanguageModal>
</div>
